<html>
<head>
	<meta charset='utf-8' />
	<title>后台管理</title>
	<meta http-equiv="keywords" content="求职,招聘,房屋,出租,出售,求租,求购,宠物,二手,二手车,二手物品,旧货,寻物,寻人,出兑,外兑"> 
	<meta http-equiv="description" content="便民信息网,房屋租售,宠物交易,二手物品,二手车辆,寻物寻人,出兑信息">  
	<meta name="description" content="便民信息网,房屋租售,宠物交易,二手物品,二手车辆,寻物寻人,出兑信息"/>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		@media screen and (max-width:450px){
			#nav_bottom{width:98%;margin:0 auto}
			#content{width:98%;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#nav_bottom{width:450px;margin:0 auto}
			#content{width:450px;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		.info_item{color:#444;margin:15px 0;display:flex}
		.info_item > div:last-child{flex:1}
	</style>
</head>
<body style='padding:0;margin:0;background:#eee'>
<!-- 1 Content容器 -->
<div id='Content'>
	<!-- 3 内容区-->
	<div style='margin:10px 0;word-break:break-all;padding:10px;'>
		<div style='float:right;text-align:right' onclick='After_Admin_Exit()'>退出</div>

		<h2 style='text-align:center;'>后台管理-分组管理</h2>
		
	

		<div style='margin:10px auto'>
			<span id='after_fun_select'>

			</span>
			<span style='float:right'>
				<button id='admin_group_add_btn'>新增分组</button>
			</span>
		</div>
		<div id='admin_group_add_area' style='display:none'>
			<div>
				组名：<input type="text" id='admin_group_add_inp_group' />
			</div>
			<div>
				说明：<input type="text" id='admin_group_add_inp_explain' />
			</div>
			<button id='admin_group_add_sub'>提交</button>
			<button id='admin_group_add_back'>返回</button>
		</div>

		<hr>

		<!--列表区-->
		<div id='group_list'></div>




		<!--修改密码浮动区-->
		<div id='admin_group_fun_list' style='width:350px;position:fixed;top:100px;border:1px solid #AAA;background:#fff;padding:20px;display:none'>
			<div>权限设置</div>
			<div id='funs_list'></div>
		</div>
		
		<div style='height:100px'></div>
				

	</div>	<!-- 3 内容区结束-->	

</div><!-- 1 Content容器结束 -->







<!--底部导航容器-->
<div id='Nav_Bottom' style='position:fixed;bottom:0;width:100%;height:45px'>



</body>
</html>


<script src='./Public/jquery.js'></script>
<script src='./Public/fun.js'></script>
<script>

	Check_After_User_Cookie();	//检测登陆状态
	
	var priv_name = 'after_set_group';
	Priv_Check(priv_name,function(res){
		if(res != 'ok'){
			alert('没有权限!');
			//location.href = document.referrer;
			exit;
		}
	});




	After_Fun_Select();	//加载后台设置页中的功能选择



	//加载底部导航栏
	Load_NavBottom('after');

	$(function(){
		//获取管理员列表
		After_Get_Group_List();




		//### 新增分组相关
		$('#admin_group_add_btn').click(function(){
			var priv_name = 'AfterSetGroup_GroupAdd';
			Priv_Check(priv_name,function(res){
				if(res != 'ok'){
					alert('没有权限!');
					//location.href = document.referrer;
					exit;
				}
			});
			$(this).hide();
			$('#admin_group_add_area').show();
		});

		//提交
		$('#admin_group_add_sub').click(function(){
			var group = $('#admin_group_add_inp_group').val().trim();
			var explain = $('#admin_group_add_inp_explain').val().trim();
			if(!group){
				alert('不得为空！');return;
			}
			group = ChangeChar(group);
			explain = ChangeChar(explain); 	//检测并转换特殊字符
			explain = ChangeChar(explain);
			var type = 'After_Admin_Group_Add';
			Token(type,function(token){
				$.ajax({
					url:url,
					type:'post',
					data:{
						token:token,
						type:type,
						group:group,
						explain:explain
					},
					success(res){
						switch(res){
							case 'err':
								alert('分组名已存在！');
								break;
							case 'ok':
								alert('分组添加成功！');
								$('#admin_group_add_area').hide();
								$('#admin_group_add_btn').show();
								After_Get_Group_List();
								break;
						}
					}
				});
			});
		});

		//返回
		$('#admin_group_add_back').click(function(){
			$('#admin_group_add_area').hide();
			$('#admin_group_add_btn').show();
		});





	});




	//删除分组
	function Group_Del(gid){
		var priv_name = 'AfterSetGroup_GroupDel';
		Priv_Check(priv_name,function(res){
			if(res != 'ok'){
				alert('没有权限!');
				//location.href = document.referrer;
				exit;
			}
		});
		if(!confirm('确认删除该组?')){
			return;
		}
		var type = 'After_Group_Del';
		Token(type,function(t){
			$.ajax({
				url:url,
				type:'post',
				data:{
					token:t,
					type:type,
					gid:gid
				},
				success(res){
					if(res == 'ok'){
						alert('删除成功!');
						After_Get_Group_List();
					}else{
						alert('删除失败!');
					}
				}
			});
		});
	}















	//获取管理员列表 
	function After_Get_Group_List(){
		var type = 'After_Get_Group_List';
		Token(type,function(t){
			$.ajax({
				url:url,
				type:'post',
				data:{
					token:t,
					type:type
				},
				success(res){
					if(res == 'err'){
						return;
					}
					var group_list = JSON.parse(res);
					var str = '';
					for(var i=0;i<group_list.length;i++){
						str += "<div style='border-bottom:1px solid #ccc;margin:5px auto;padding-bottom:20px;'>";
						str += "<div>组名："+group_list[i][1]+"</div>";
						str += "<div>说明："+group_list[i][2]+"</div>";
						str += "<div style='text-align:right' class='user_con_btns'>";
						str += "<button onclick=Cat_Group_User("+group_list[i][0]+",'"+group_list[i][1]+"')>查看成员</button>";
						str += " <button onclick=Cat_Group_Grant("+group_list[i][0]+",'"+group_list[i][1]+"')>查看权限</button> ";
						str += "<button onclick=Group_Del("+group_list[i][0]+")>删除</button>";
						str += "</div>";
						str += "</div>";
					}
					$('#group_list').html(str);

				}
			});
		});
	}





	//查看组权限
	function Cat_Group_Grant(gid,gname){
		location.href='after_set_group_set_fun.html?gid='+gid+"&gname="+gname;
	}

	function Cat_Group_User(gid,gname){
		location.href='after_set_group_set_user.html?gid='+gid+"&gname="+gname;
	}
	

</script>

